/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RENDER_STATS_HH
#define RENDER_STATS_HH
//! \addtogroup introsight_framework
//@{

// INCLUDES
#include "util.hh"
#include "refcnt.hh"
#include "render_mng.hh"

#define RS_MAX_BUFFER    32

enum render_stats_type
{
    RS_N_PASS=0,   // should be the first
    RS_TIME_LAST,
    RS_TIME_MAX,
    RS_TIME_MEAN,
    RS_TIME_ACCUM,
    RS_OBJ_LAST,
    RS_OBJ_MAX,
    RS_OBJ_MEAN,
    RS_OBJ_ACCUM,
    RS_LAST,
};

class render_stats: public reference_counter
{
    struct pass_str
    {
	int n;

	// counter of render_obj::render_init / pass
	unsigned render_init;
	unsigned render_init_max;
	unsigned render_init_accum;

	// time measures
	double time;         // last time measured (msec)
	double time_max;     // max time (msec)
	double time_accum;   // accumulated time (accum)

	unsigned time_start; // (usec)

    } passv[RENDER_PASS_LAST_ALL];

    render_stats_type stats_type;

    // PRIVATE METHODS
    void ctor();
    void dtor();

public:
    render_stats();
    virtual ~render_stats();

    bool init();

    void reset();

    // event count
    inline void inc_pass(render_pass p) {passv[p].n++;}

    inline void inc_render_init(render_pass p) {passv[p].render_init++;}
    void reset_render_init(render_pass p);

    // time events
    void clock(render_pass p);
    void clock_stop(render_pass p);

    // type of stats
    inline void set_stats_type(render_stats_type type) {stats_type=type;}
    void inc_stats_type();
    void dec_stats_type();

    // getters
    char *get_current_stat(render_pass p, char buffer[RS_MAX_BUFFER]);
    const char *get_current_stat_str();

    inline unsigned get_render_init(render_pass p) {return passv[p].render_init;}
    inline unsigned get_render_init_max(render_pass p) {return passv[p].render_init_max;}

    inline unsigned get_clock(render_pass p) {return passv[p].time_start;}
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	render_stats
	{
		# members
		passv,
		stats_type:
						select, read_only

		# methods
		init, reset:
						select
	}
   )
*/
